package gao.xiaolei.dao;

import gao.xiaolei.entity.TestPersonalGrade;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository("TestPersonalGradeDao")
public interface TestPersonalGradeDao extends JpaRepository<TestPersonalGrade, String> {

    @Modifying
    public void deleteAllByProject(String project);

    public TestPersonalGrade findByUserIdAndProject(String userId, String project);

    public TestPersonalGrade findByUserIdAndProjectAndIsPublic(String userId, String project, Boolean isPublic);

    public List<TestPersonalGrade> findAllByUserIdInAndProject(List<String> userId, String project);

    @Modifying
    @Query("update TestPersonalGrade set isPublic=:isPublic where project=:projectId")
    public void updateIsPublic(@Param("isPublic") Boolean isPublic,
                               @Param("projectId") String projectId);
}
